Ext.onReady(function(){
    var pnrField = new Ext.form.TextField({
        fieldLabel: 'PNR',
        name: 'pnr',
		allowBlank: true,
        //anchor: '90%',
        width: 60
    });
    var cancelFromDate = new Ext.form.DateField({
        fieldLabel: '日期从',
        name: 'cancel_from_date',
        id: 'cancel_from_date',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        blankText: '开始日期必须选择',
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //applyTo: 'cancel_date',
        vtype: 'daterange',
        endDateField: 'cancel_to_date',
        //anchor: '95%',
        width: 90
        //,value: today
    });
    var cancelToDate = new Ext.form.DateField({
        fieldLabel: '到',
        name: 'cancel_to_date',
        id: 'cancel_to_date',
        altFormats: 'Y-m-d',
        format: 'Y-m-d', //格式化日期
        //disabledDays: [0,6],	//不让选择周六，周日
        //disabledDaysText: "周末要休息",
        invalidText: "您输入的日期格式不对，正确格式为2008-01-01",
        allowBlank: false,
        blankText: '截止日期必须选择',
        //emptyText: '请选择...',
        inputType: '2008-01-01',
        //applyTo: 'cancel_date2',
        vtype: 'daterange',
        startDateField: 'cancel_from_date',
        //anchor: '95%',
        width: 90
        //,value: today
    });
    
    var myCancel = new Ext.form.Checkbox({
        fieldLabel: '我的取消单',
        hideLabel: true,
        boxLabel: '我的取消单',
        name: 'my_cancel',
        checked: true,
        anchor: '100%'
    });
    
    var queryButton = new Ext.Button({
        text: '查 询',
        handler: function(){
            if (formPanel.form.isValid()) {
                var isMy = "";
                if (myCancel.checked) {
                    isMy = "yes";
                }
                
                cancel_orderds.baseParams.pnr = pnrField.getValue();
                cancel_orderds.baseParams.isMyOrder = isMy;
                cancel_orderds.baseParams.cancel_date = cancelFromDate.getValue().format('Y-m-d');
                cancel_orderds.baseParams.cancel_date_to = cancelToDate.getValue().format('Y-m-d');
                cancel_orderds.reload();
                cancel_ticketds.baseParams.id = "";
                cancel_ticketds.reload();
            }
        }
    });
    
    var formPanel = new Ext.form.FormPanel({
        //baseCls: 'x-plain',
        labelWidth: 40,
        width: '100%',
        frame: true,
        labelAlign: 'right',
        items: [{
            layout: 'column',
            border: false,
            items: [{
                columnWidth: .12,
                layout: 'form',
                border: false,
                items: [pnrField]
            }, {
                columnWidth: .17,
                layout: 'form',
                border: false,
                items: [cancelFromDate]
            }, {
                columnWidth: .17,
                layout: 'form',
                border: false,
                items: [cancelToDate]
            }, {
                columnWidth: .15,
				lableWidth: 0,
                layout: 'form',
                border: false,
                items: [myCancel]
            }, {
                columnWidth: .2,
                layout: 'form',
                border: false,
                items: [queryButton]
            }]
        }]
    });
    
    formPanel.render('search_cancel_form');
    
    //############## 订单Grid ##############
    var cancel_ordercm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
        header: '编号',
        dataIndex: 'id',
        hidden: true
    }, {
        header: '订单编号',
        dataIndex: 'order_no',
        width: 115
    }, {
        header: 'PNR',
        dataIndex: 'pnr',
        width: 60
    }, {
        header: '客户名称',
        dataIndex: 'customer',
        width: 70
    }, {
        header: '订单状态',
        dataIndex: 'status',
        width: 60
    }, {
        header: '总金额',
        dataIndex: 'price_sum',
        width: 60
    }, {
        header: '预定人',
        dataIndex: 'creator',
        width: 70
    }, {
        header: '预定时间',
        dataIndex: 'created_at',
        width: 110,
        renderer: Ext.util.Format.dateRenderer('Y-m-d H:i')
    }, {
        header: '出票人',
        dataIndex: 'ticket_outer',
        width: 70,
        hidden: true
    }, {
        header: '取消人',
        dataIndex: 'canceler',
        width: 70
    }, {
        header: '取消时间',
        dataIndex: 'cancel_date',
        width: 110,
        renderer: Ext.util.Format.dateRenderer('Y-m-d H:i')
    }, {
        header: '取消原因',
        dataIndex: 'cancel_reason',
        width: 120
    
    }]);
    cancel_ordercm.defaultSortable = true;
    var cancel_orderds = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: '/orders/getCancelOrdersBySearch'
        }),
        reader: orderReader
    });
    
    var ordergridpanel = new Ext.grid.GridPanel({
        el: 'cancelOrdersGrid',
        ds: cancel_orderds,
        cm: cancel_ordercm,
        //sm: sm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 310,
        //frame: true,
        title: '订单信息',
        bbar: new Ext.PagingToolbar({
            pageSize: 10,
            store: cancel_orderds,
            displayInfo: true,
            displayMsg: '显示第 {0} 条到 {1} 条记录，一共 {2} 条',
            emptyMsg: "没有记录"
        })
    
    });

    ordergridpanel.render();
    //ds.load();
    cancel_orderds.load({
        params: {
            start: 0,
            limit: 10
        }
    });
    
    //双击订单查看票详细
    ordergridpanel.on('rowdblclick', function(ordergridpanel, rowIndex, e){
        var current_order_selected = cancel_orderds.data.items[rowIndex].id;
        var ordersrow = cancel_orderds.getById(current_order_selected);//ds为绑定到grid的数据源 
        var current_order_id = ordersrow.get("id");
        cancel_ticketds.baseParams.id = current_order_id;
        cancel_ticketds.reload();
    });
    
    //### 机票Grid ###
    var cancel_ticketcm = new Ext.grid.ColumnModel([new Ext.grid.RowNumberer(), {
        header: '编号',
        dataIndex: 'id',
        hidden: true
    }, {
        header: 'PNR',
        dataIndex: 'pnr',
        width: 60
    }, {
        header: '旅客姓名',
        dataIndex: 'passenger_name',
        width: 70
    }, {
        header: '证件号码',
        dataIndex: 'card',
        width: 140
    }, {
        header: '票号',
        dataIndex: 'ticket_no',
        width: 110
    }, {
        header: '状态',
        dataIndex: 'status_type',
        width: 50
	}, {
        header: '出票状态',
        dataIndex: 'status',
        width: 60
    }, {
        header: '航班号',
        dataIndex: 'air_no',
        width: 70
    }, {
        header: '航程',
        dataIndex: 'fromto',
        width: 60
    }, {
        header: '乘机日期',
        dataIndex: 'fly_date',
        width: 70
    }, {
        header: '起飞时间',
        dataIndex: 'fly_time',
        width: 60
    }, {
        header: '舱位',
        dataIndex: 'position',
        width: 40
    }, {
        header: '机票价格',
        dataIndex: 'price',
        width: 60
    }, {
        header: '机场费税',
        dataIndex: 'airdrome_tax',
        width: 60
    }, {
        header: '附加费',
        dataIndex: 'fuel_tax',
        width: 60
    }, {
        header: 'F',
        dataIndex: 'price_F',
        width: 40
    }, {
        header: '保险份数',
        dataIndex: 'insurance_number',
        width: 60
    }, {
        header: '保险F',
        dataIndex: 'insurance_F',
        width: 50
    }, {
        header: '其他',
        dataIndex: 'other',
        width: 50
    }, {
        header: '积分',
        dataIndex: 'point',
        width: 50
    }, {
        header: '合计',
        dataIndex: 'total_price',
        width: 60
    
    }]);
    cancel_ticketcm.defaultSortable = true;
    var ticketProxy = new Ext.data.HttpProxy({
        url: '/orders/getTicketsByOrderID'
    });
    
    var cancel_ticketds = new Ext.data.Store({
        proxy: ticketProxy,
        reader: ticketReader
    });
    
    var ticketgridpanel = new Ext.grid.GridPanel({
        el: 'cancelTicketsGrid',
        ds: cancel_ticketds,
        cm: cancel_ticketcm,
        //sm: sm,
        loadMask: true,
        autoWidth: true,
        collapsible: true,
        animCollapse: true,
        height: 180,
        //frame: true,
        title: '航班信息'
    });
    
    ticketgridpanel.render();
    cancel_ticketds.load();
})
